<template>
	<view >
		<view class="search-item" v-for="(s,i) in foodSearchList" :key="i">
			<text class="search-name">{{s.name}}</text>
			<view class="search-img" @click="goFood(s.foodId)">
				<image class="img-item" :src='s.picture'></image>
			</view>
			<view class="desc">
				<text class="desc-item"> {{s.hits}} 人浏览</text>
				<text class="desc-item">{{s.favorites}}收藏</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value:'',
				foodSearchList:[]
			}
		},
		props:{name:String},
		methods: {
			getData(){
	
						uni.request({
							url: `https://appfly.cn/api/cookbookCommon/foodSearch?keyword=${this.name}`,
						
							success: (res) => {
								this.foodSearchList = res.data.data
								// console.log(res.data);//输出
								// console.log(this.foodSearchList);
							}
						});
			},
			
			goFood(id){
				uni.navigateTo({
				     url:`/pages/food/food?id=${id}`
				 })
			}
		},
		mounted() {
			this.getData()
			// console.log(this.time);
		},
	}
</script>

<style lang="scss">
	.search-item{
		width: 93vw;
		padding: 10px 12px;
		margin-bottom: 20px;
		.search-name{
			font-size: 18px;
			font-weight: 700;
		}
		.search-img{
			width: 93vw;
			height: 200px;
			border-radius: 8px;
			margin: 10px 0;
			
		
			.img-item {
				width: 100%;
				height: 100%;
				border-radius: 8px;
			}
		
		}
		.desc{
			width: 93vw;
			display: flex;
			justify-content: space-between;
			color: #999;
		}
	}
</style>